package com.kucai.yifaqapp.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.Resgetuser;
import com.kucai.yifaqapp.util.OnItemClickListener;
import com.kucai.yifaqapp.util.PriceUtils;
import com.kucai.yifaqapp.util.SYSOUtils;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by admin on 2018/12/20.
 */

public class RecommentFragmentthree extends BaseFragmentSimple {
    @BindView(R.id.deposite_rl)
    RecyclerView depositeRl;
    private MyAdapter adapter;
    private Resgetuser mDatas;

    @Override
    protected int setContentView() {
        return R.layout.fragment_recomment_03;
    }

    @Override
    protected void ChangeSkin() {

    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SYSOUtils.sOut_("2222222222222222222222222");
        getdata();
        depositeRl.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new MyAdapter();
        depositeRl.setAdapter(adapter);
    }

    private void getdata() {

        HttpJsonUtils.getHttpApiInstance()
                .getmyuser(HttpAdress.getuseAdress() + "api/m/pc/bet/getLookUser",Info.user.token, "", "1", "100")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resgetuser>(this) {
                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {

                    }

                    @Override
                    protected void onCustomNext(Resgetuser resCode) {
                        if (resCode.code == 0 && resCode.data != null) {
                            mDatas = resCode;
                            depositeRl.setAdapter(adapter);
                        }

                    }
                });
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////
    class MyAdapter extends RecyclerView.Adapter<MyAdapter.MViewHolder>
            implements OnItemClickListener {
        @Override
        public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new MViewHolder(LayoutInflater.from(getContext())
                    .inflate(R.layout.deposite_item, parent, false));

        }

        @Override
        public void onBindViewHolder(final MViewHolder holder, final int position) {
            try {
                holder.time_tv.setText(mDatas.data.get(position).username);
                holder.rechmoney.setText(mDatas.data.get(position).fullName);
//                status : 状态 1未受理 2充值成功 3充值失败 4在线充值中
                holder.states.setText(mDatas.data.get(position).money);
                PriceUtils.format(holder.states);
            } catch (Exception e) {

            }
        }

        @Override
        public int getItemCount() {
            return mDatas.data.size();
        }

        @Override
        public void onItemClick(View view, int position) {

        }

        class MViewHolder extends RecyclerView.ViewHolder {
            TextView time_tv;
            TextView rechmoney;
            TextView states;

            MViewHolder(View itemView) {
                super(itemView);
                time_tv = (TextView) itemView.findViewById(R.id.time_tv);
                rechmoney = itemView.findViewById(R.id.rechmoney);
                states = itemView.findViewById(R.id.states);

            }
        }
    }

}
